package com.wpf.test02;

public class Student {
    private String name;
    private String sex;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        if(sex.equals("男")|| sex.equals("女")){
            this.sex = sex;
        }else {
            System.out.println("性别异常");
            throw new SexException(sex + "不是'男' 或'女'");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age >=15&& age <=50){
            this.age = age;
        }else {
            throw new AgeException("年龄异常"+ "["+age+"]" + "不在15-50范围以内");
        }
    }

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        if(sex.equals("男")|| sex.equals("女")){
            this.sex = sex;
        }else {
            throw new SexException("性别异常"+ "["+sex+"]" + "不是'男' 或'女'");
        }
        if(age >=15&& age <=50){
            this.age = age;
        }else {
            throw new AgeException("年龄异常"+ "["+age+"]" + "不在15-50范围以内");
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}
